/**
 * @file exercise_sport_test.h
 * note: only for ui demostration
 */

#ifndef EXERCISE_SPORT_TEST_H
#define EXERCISE_SPORT_TEST_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
*      INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "../../../lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif

#if USE_LV_WATCH_EXERCISE != 0

//#include "lv_watch.h"
#include <stdio.h>
#include "../../../lvgl/hal/hal.h"

/*********************
*      DEFINES
*********************/
#define EXERCISE_TEST_MODE 1

#if EXERCISE_TEST_MODE != 0

/**********************
*      MACROS
**********************/
#define EXERCISE_TEST_HR_ZONE_NUM        (5)

#define EXERCISE_TEST_VO2MAX_ZONE_NUM    (7)

#define EXERCISE_TEST_CURVE_NODE_NUM     (240)

/**********************
*      TYPEDEFS
**********************/
typedef void (*EXERCISE_TEST_SPORT_PREPARE_CNF)(void);

enum {
    EXERCISE_TEST_TYPE_OUTDOOR_RUNNING = 0,
    EXERCISE_TEST_TYPE_OUTDOOR_CYCLING,
    EXERCISE_TEST_TYPE_WALKING,
    EXERCISE_TEST_TYPE_FREE_TRAINING,
};
typedef uint8_t EXERCISE_TEST_TYPE_T;

// for updating ui
typedef struct {
    uint32_t duration;                  // in seconds
    uint32_t hr_value;
    uint32_t pace_value;                // in seconds / km
    uint32_t aver_pace_value;           // in seconds / km
    uint32_t distance_value;            // in meters
    uint32_t calorie_value;             // in kcal
    uint32_t step_num_value;            // in steps
    uint32_t stride_freq_value;         // in steps / min
    uint32_t climb_value;               // in dm
    uint32_t height_value;              // in dm
    uint32_t speed_value;               // in meters / hour
    uint32_t aver_speed_value;          // in meters / hour
    uint8_t aerobic_training_value;     // 10 to 50, real value 1.0 to 5.0
    uint8_t anaerobic_training_value;   // 10 to 50, real value 1.0 to 5.0
} exercise_test_sport_data_t;

// sport record
typedef struct {
    uint16_t top_speed;                                 // in meters / hour
    uint16_t speed[EXERCISE_TEST_CURVE_NODE_NUM];       // in meters / hour
} exercise_test_record_speed_t;

typedef struct {
    uint16_t max_pace;                                  // in seconds / km
    uint16_t pace[EXERCISE_TEST_CURVE_NODE_NUM];        // in seconds / km
} exercise_test_record_pace_t;

typedef struct {
    uint32_t step_number;
    uint32_t aver_stride;                               // in CM
    uint8_t max_stride_freq;
    uint8_t min_stride_freq;
    uint8_t aver_stride_freq;
    uint8_t stride_freq[EXERCISE_TEST_CURVE_NODE_NUM];
} exercise_test_record_step_t;

typedef struct {
    uint16_t climb_height;                              // in dm
    uint16_t decline_height;                            // in dm
    uint16_t max_altitude;                              // in dm
    uint16_t min_altitude;                              // in dm
    uint16_t aver_altitude;                             // in dm
    uint16_t height[EXERCISE_TEST_CURVE_NODE_NUM];      // in dm
} exercise_test_record_height_t;

typedef struct {
    uint8_t vo2max;                                     // in ml/kg/min
    uint8_t zone[EXERCISE_TEST_VO2MAX_ZONE_NUM + 1];
} exercise_test_record_vo2max_t;

typedef struct {
    EXERCISE_TEST_TYPE_T type;
    uint32_t total_disctance;                           // in meters
    uint32_t sport_time;                                // in seconds
    uint32_t calorie;                                   // in kcal
    uint16_t aver_speed;                                // in meters / hour
    uint16_t aver_pace;                                 // in seconds / km
    uint8_t max_hr;
    uint8_t min_hr;
    uint8_t aver_hr;
    uint8_t hr[EXERCISE_TEST_CURVE_NODE_NUM];
    uint16_t hr_zone_time[EXERCISE_TEST_HR_ZONE_NUM];   // in minutes
    uint8_t aerobic_training_value;                     // 10 to 50, real value 1.0 to 5.0
    uint8_t anaerobic_training_value;                   // 10 to 50, real value 1.0 to 5.0
    uint32_t recovery_time;                             // in seconds
    uint32_t max_recovery_time;                         // in seconds
    exercise_test_record_speed_t * speed;
    exercise_test_record_pace_t * pace;
    exercise_test_record_step_t * step;
    exercise_test_record_height_t * height;
    exercise_test_record_vo2max_t * vo2max;
} exercise_test_record_t;

/**********************
* GLOBAL PROTOTYPES
**********************/
void exercise_test_sport_prepare_req(EXERCISE_TEST_TYPE_T type, EXERCISE_TEST_SPORT_PREPARE_CNF cb);
void exercise_test_sport_start_req(void);
void exercise_test_sport_stop_req(exercise_test_record_t * data);
void exercise_test_get_hr_zone(uint8_t * hr_zone); // hr_zone[EXERCISE_TEST_HR_ZONE_NUM + 1]
void exercise_test_get_sport_data(exercise_test_sport_data_t * data);
uint8_t exercise_test_prepare_to_stop_sport(void);

#endif /*EXERCISE_TEST_MODE*/

#endif /*USE_LV_WATCH_EXERCISE*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*EXERCISE_SPORT_TEST_H*/
